﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZooKeeperNet;

namespace dis.sys.hw1.Service
{
    public class WatchMyBackup : IWatcher
    {
        private readonly ServiceLog _log = new ServiceLog(typeof(WatchMyBackup), true);

        private HotelService hotelService;

        public WatchMyBackup(HotelService hotelService)
        {
            this.hotelService = hotelService;
        }
        

        public void Process(WatchedEvent @event)
        {
            _log.Debug("WatchMyBackup");
            _log.Debug(hotelService.ServerData.MainHotelName + " Got event - " + @event.Type + " - path: " + @event.Path);
            if (@event.Type.Equals(EventType.NodeDeleted))
            {
                hotelService.BackupData();
            }
            else
            {
                hotelService.Replicator.GetData(@event.Path, this, null);
            }
        }
    }
}
